import { CommonUtils } from '../utils/commonutils';

export enum CanvasMode {
    Drawing,
    Eraser,
    Move,
    None,
}
export class StrokeCollection {
    private strokes: Stroke[] = [];
    constructor(strokes?: Stroke[]) {
        if (strokes && strokes.length > 0) {
            this.strokes.concat(strokes);
        }
    }
    addStroke(stroke: Stroke) {
        if (stroke) {
            this.strokes.push(stroke);
        }
    }
    addStrokes(strokes: Stroke[]) {
        if (strokes && strokes.length > 0) {
            this.strokes.concat(strokes);
        }
    }
    findStroke(guid: string): Stroke {
        if (this.strokes && this.strokes.length > 0) {
            return this.strokes.find((stroke, index) => stroke.guid === guid);
        }
        return null;
    }
    clear() {
        this.strokes.splice(0, this.strokes.length);
    }
}
export class Stroke {
    guid: string;
    points: StrokePoint[] = [];
    strokeWidth: number;
    strokeColor: string;
    constructor() {
        this.guid = CommonUtils.guid();
        this.strokeWidth = 2;
        this.strokeColor = '#000000';
    }
    addStrokePoint(point: StrokePoint) {
        this.points.push(point);
    }
    addPoint(x: number, y: number, factor?: number) {
        this.points.push(new StrokePoint(x, y, factor));
    }
    clear() {
        this.points.splice(0, this.points.length);
    }
}
export class StrokePoint {
    x: number;
    y: number;
    factor: number;
    constructor(x: number, y: number, factor?: number) {
        this.x = x;
        this.y = y;
        this.factor = typeof(factor) === 'undefined' ? 0.5 : factor;
    }
}
